import React, { Component } from 'react'
import MainProductList from './MainProductList'
import MainBanner from './MainBanner'
import axios from 'axios'
// 父组件->子组件通信: 子组件在constructor构造函数中props中可以拿到，当子组件没有状态(state)时，可以省略构造函数也可以拿到props
class main extends Component {
  constructor() {
    super()
    this.state = {
      banner: [],
      productList: []
    }
  }
  componentDidMount() {
    axios.get('http://123.207.32.32:8000/home/multidata').then(res => {
      console.log(res);
      const banner = res.data.data.banner.list
      const recommend = res.data.data.recommend.list
      this.setState({
        banner,
        productList: recommend
      })

    })
  }
  render() {
    const {banner , productList} = this.state
    return (
      <div className='main'>
        <MainBanner banner={ banner} title="轮播图"/>
        <MainBanner />
        <MainProductList productList={productList} />
    </div>
    )
  }
}

export default main